import React, { PropTypes, Component } from 'react'
import WidgetImage from './WidgetImage'
import WidgetIntro from './WidgetIntro'
import WidgetSwiper from './WidgetSwiper'

class WidgetContainer extends Component {
  constructor(props, context) {
    super(props, context)
    this.state={

    }

  }



   widgetRender(){
    let { widgets }=this.props
    return widgets.map((widget,i)=>{
       widget.componentId=this.props.positionId
       widget.positionId=i

       switch (widget.id) {
        case 1:{
            return widget.enable? <WidgetImage key={widget.positionId} 
                                               widget={widget} 
                                               handleWidgetMenuShow={this.props.handleWidgetMenuShow.bind(this)} />:null
            
        }
     
        case 2:{
         return  widget.enable?<WidgetIntro key={widget.positionId} 
                                            widget={widget} 
                                            handleWidgetMenuShow={this.props.handleWidgetMenuShow.bind(this)} />:null
          
             
        }
     
        case 3:{
         return  widget.enable?<WidgetSwiper key={widget.positionId} 
                                            widget={widget} 
                                             handleWidgetMenuShow={this.props.handleWidgetMenuShow.bind(this)}
                                            />:null
          
             
        }

       }

      })
   }


  render() {
   return (
     <div className="widget-wrap">
       {this.widgetRender()}
    </div>
    )
  
   
  }
}

WidgetContainer.propTypes = {
  widgets:PropTypes.array,
  handleWidgetMenuShow:PropTypes.func
}

export default WidgetContainer
